﻿using System;
using DepIC;

namespace TeF.Runner.Services
{
    internal static class IoCHelper
    {
        private static IContainer _container;
        
        public static IReadOnlyContainer Container
        {
            get
            {
                if (_container == null)
                {
                    _container = ContainerFactory.Create();
                    RegisterServices(_container);
                }
                
                return _container;
            }
        }

        private static void RegisterServices(IContainer container)
        {
            if (container == null)
                throw new ArgumentNullException("container");

            container.SetImplementation<ISystemDateTime, SystemDateTime>(Lifetime.PerContainer);
            container.SetImplementation<ITestAssemblyLoader, TestAssemblyLoader>(Lifetime.PerContainer);
            container.SetImplementation<ITestFinder, TestFinder>(Lifetime.PerContainer);

            container.SetImplementation<ITestRunner, TestRunner>(Lifetime.PerCall);

            container.SetImplementation<IReportCreator, ReportCreator>(Lifetime.PerContainer);
        }
    }
}
